package com.yhd.controller;

import com.yhd.entity.dto.SystemDictionaryDto;
import com.yhd.entity.query.SystemDictionaryVO;
import com.yhd.entity.result.ResultVo;
import com.yhd.model.ResultPage;
import com.yhd.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "字典管理")
@Slf4j
@RequestMapping(value = "/dict")
@CrossOrigin
public class SysDictController extends WebBaseController {

    @Autowired
    private SysDictService sysDictService;



    @ApiOperation(value = "获取字典列表", notes = "获取字典列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "groupId", value = "类型：100课程分类 200活动分类，300课程协议，400活动协议， 500师资团队", required = true, paramType = "字符串"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示数量", required = true, paramType = "int")})
    @GetMapping("/list")
    @ResponseBody
    public ResultVo<ResultPage<List<SystemDictionaryDto>>> selectSysDictList(SystemDictionaryVO systemDictionaryVO){
        ResultPage<List<SystemDictionaryDto>> resultPage = sysDictService.selectSysDictList(systemDictionaryVO);
        return ResultVo.success(resultPage);
    }

    @ApiOperation(value = "获取字典详情", notes = "获取字典详情")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "字典id", required = true, paramType = "字符串")})
    @GetMapping("/info")
    @ResponseBody
    public ResultVo<SystemDictionaryDto> selectSysDictInfo(SystemDictionaryVO systemDictionaryVO){
        SystemDictionaryDto systemDictionaryDto = sysDictService.selectSysDictInfo(systemDictionaryVO);
        return ResultVo.success(systemDictionaryDto);
    }

    @ApiOperation(value = "新增字典", httpMethod = "POST", notes = "{\n" +
            "  \"name\": \"名字\",\n" +
            "  \"groupId\": \"类型：100课程分类 200活动分类，300课程协议，400活动协议\",\n" +
            "  \"sort\": \"排序\"\n" +
            "}")
    @PostMapping("/add")
    @ResponseBody
    public ResultVo<SystemDictionaryDto> addSysDict(@RequestBody SystemDictionaryVO systemDictionaryVO) {
        SystemDictionaryDto systemDictionaryDto = sysDictService.addSysDict(systemDictionaryVO,getUserInfo(request));
        if (null != systemDictionaryDto){
            return ResultVo.success(systemDictionaryDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "修改字典", httpMethod = "PUT", notes = "{\n" +
            "  \"id\": \"字典\",\n" +
            "  \"name\": \"名字\",\n" +
            "  \"groupId\": \"类型：100课程分类 200活动分类，300课程协议，400活动协议， 500师资团队\",\n" +
            "  \"sort\": \"排序\"\n" +
            "}")
    @PutMapping("/update")
    @ResponseBody
    public ResultVo<SystemDictionaryDto> updateSysDict(@RequestBody SystemDictionaryVO systemDictionaryVO) {
        SystemDictionaryDto systemDictionaryDto = sysDictService.updateSysDict(systemDictionaryVO,getUserInfo(request));
        if (null != systemDictionaryDto){
            return ResultVo.success(systemDictionaryDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }

    @ApiOperation(value = "删除字典", httpMethod = "DELETE", notes = "{\n" +
            "  \"id\": \"字典id\"\n" +
            "}")
    @DeleteMapping("/delete")
    @ResponseBody
    public ResultVo<SystemDictionaryDto> deleteSysDict(@RequestBody SystemDictionaryVO systemDictionaryVO) {
        SystemDictionaryDto systemDictionaryDto = sysDictService.deleteSysDict(systemDictionaryVO,getUserInfo(request));
        if (null != systemDictionaryDto){
            return ResultVo.success(systemDictionaryDto);
        }
        return ResultVo.failure("10003","操作失败。");
    }


    @ApiOperation(value = "获取全部分类列表", notes = "获取全部分类列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "groupId", value = "组id100课程分类 200活动分类 500师资团队", required = true, paramType = "字符串")})
    @GetMapping("/allClassify")
    @ResponseBody
    public ResultVo<List<SystemDictionaryDto>> selectAllClassifyList(SystemDictionaryVO systemDictionaryVO){
        List<SystemDictionaryDto> resultPage = sysDictService.selectAllClassifyList(systemDictionaryVO);
        return ResultVo.success(resultPage);
    }


}
